#ifndef utility_TimeSpec_h
#define utility_TimeSpec_h

#include <time.h>

#ifndef CLOCK_REALTIME
# define CLOCK_REALTIME 0
#endif

namespace serika
{
	namespace ut
	{
		struct TimeSpec
	#ifndef WIN32
			: public timespec
	#endif
		{
		public:
	#ifdef WIN32
			time_t tv_sec;
			long tv_nsec;
	#endif
	
			TimeSpec();
			TimeSpec(const TimeSpec& other);
			bool operator < (const TimeSpec& other) const;
			bool operator == (const TimeSpec& other) const;
			bool operator != (const TimeSpec& other) const;
			bool operator > (const TimeSpec& other) const;
			bool operator <= (const TimeSpec& other) const;
			bool operator >= (const TimeSpec& other) const;
			TimeSpec& operator = (const TimeSpec& other);
			TimeSpec operator - (const TimeSpec& other) const;
			TimeSpec operator + (const TimeSpec& other) const;
			TimeSpec& operator -= (const TimeSpec& other);
			TimeSpec& operator += (const TimeSpec& other);
	
			double ToSeconds() const;
			void Reload();
	
			static const TimeSpec& Now(int clockid = CLOCK_REALTIME);
			static const TimeSpec& MakeTimeout(long msec, int clockid = CLOCK_REALTIME);
	
		private:
			inline void Normalize();
		};
	}
}

#endif
